package com.sto.stoapp.activity.administrator;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.sto.stoapp.activity.R;
import com.sto.stoapp.broadcast.HomeBroadAction;
import com.sto.stoapp.db.StoFilePreference;
import com.sto.stoapp.listener.StoOnClickListener;
import com.sto.stoapp.util.Helper;
import com.sto.stoapp.widget.StoHhmEditText;
import com.sto.stoapp.widget.StoHhmEditText.EditClickListener;
import com.sto.stoapp.widget.StoHomeActivity;
public class SettingGpsTimeActivity extends StoHomeActivity {

	private Button saveBtn;

	private StoHhmEditText gpsTimeEdit;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.gps_time_settings);
		this.setTitleBottom(R.string.gps_auto_load,
				HomeBroadAction.ADMINISTRATOR_BROAD);
		initWidget();
		initListener();
	}

	private void initListener() {
	    /*
	     * 添加小退
	     */
	    gpsTimeEdit.setEditDelete(new EditClickListener() {
            
            @Override
            public void onEditDelete() {
                SettingGpsTimeActivity.this.finish();
            }
            
            @Override
            public void onEditClickListener(View v) {
                
            }
        });
		saveBtn.setOnClickListener(new StoOnClickListener(this) {

			@Override
			public void mHonClick(View view) {
				String gpsTime = gpsTimeEdit.getText().toString().trim();
				if (Helper.isNumeric(gpsTime)) {
					StoFilePreference.getInstance(SettingGpsTimeActivity.this)
							.setGpsAutoTime(gpsTime);
					Helper.showToast(SettingGpsTimeActivity.this,
							getText(R.string.save_success).toString());
					finish();
				} else {
					Helper.showToast(SettingGpsTimeActivity.this,
							getText(R.string.input_must_number).toString());
				}
			}
		});
	}

	private void initWidget() {
		saveBtn = (Button) findViewById(R.id.save);
		gpsTimeEdit = (StoHhmEditText)findViewById(R.id.gps_time_edit);
		String gpsTime = StoFilePreference.getInstance(this).getGpsAutoTime();
		gpsTimeEdit.setText(gpsTime);
		gpsTimeEdit.setSelection(gpsTime.length());
	}
}
